package fr.rinie.android_first_step;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * All copyright reserved.
 * User: romain
 * Date: 11/21/13
 * Time: 9:14 PM
 * Please contact romain.rinie@xcom.de before any modification/distribution.
 */
public class ObjectSerializer {
    /**This class has been made to simplify management of fish common name
     * As fish can have 0 to n I didn't want to manage a complicated database
     * Common name are saved as one entry in the database, the common name being separated by the character in
     * SEPARATOR**/
    //TODO: Check how to optimise Exception handling on Android
    private static final String SEPARATOR = "&";
    public List<String> deserialyze(final String serialized) {
        if (null == serialized) {
            return new ArrayList<>();
        }
        String[] strings = serialized.split(SEPARATOR);
        for (int i = 0; i < strings.length; i++) {
            try {
                strings[i] = URLDecoder.decode(strings[i], "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
        return Arrays.asList(strings);
    }
}
